//2009/09/18 17:22:02
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class ThirtyOne
{
public:
    int findWinner(vector <string> hands)
    {
        int idx = -1;
        double total = 0;
        for (int i=0; i<hands.size(); i++)
        {
            stringstream ss(hands[i]);
            string s1, s2, s3;
            int s = 0;
            double score = 0;
            ss >> s1 >> s2 >> s3;
            if (s1 == "2") score += 2;
            if (s1 == "3") score += 3;
            if (s1 == "4") score += 4;
            if (s1 == "5") score += 5;
            if (s1 == "6") score += 6;
            if (s1 == "7") score += 7;
            if (s1 == "8") score += 8;
            if (s1 == "9") score += 9;
            if (s1 == "10") score += 10;
            if (s1 == "J") score += 10;
            if (s1 == "Q") score += 10;
            if (s1 == "K") score += 10;
            if (s1 == "A") s ++;
			
			if (s2 == "2") score += 2;
            if (s2 == "3") score += 3;
            if (s2== "4") score += 4;
            if (s2 == "5") score += 5;
            if (s2 == "6") score += 6;
            if (s2 == "7") score += 7;
            if (s2 == "8") score += 8;
            if (s2 == "9") score += 9;
            if (s2 == "10") score += 10;
            if (s2 == "J") score += 10;
            if (s2 == "Q") score += 10;
            if (s2 == "K") score += 10;
            if (s2 == "A") s ++;
			
			if (s3 == "2") score += 2;
            if (s3 == "3") score += 3;
            if (s3 == "4") score += 4;
            if (s3 == "5") score += 5;
            if (s3 == "6") score += 6;
            if (s3 == "7") score += 7;
            if (s3 == "8") score += 8;
            if (s3 == "9") score += 9;
            if (s3 == "10") score += 10;
            if (s3 == "J") score += 10;
            if (s3 == "Q") score += 10;
            if (s3 == "K") score += 10;
            if (s3 == "A") s ++;
            cout << "Score:" << score << ", ";
            if (s == 3) score = 30.5;
            if (s == 2)
            {
                if (score + 22 <= 31) score +=22;
                else if (score + 12 <= 31) score += 12;
                else if (score + 2 <= 31) score += 2;
            }
            if (s == 1)
            {
                if (score + 11 <= 31) score += 11;
                else if (score + 1 <=31) score += 1;
            }
			if(s1 == s2 && s1 == s3) score = 30.5;
            if (score > total)
            {
                idx = i;
                total = score;
            }
            cout << score << endl;
        }
        return idx;
    }
};
